{% extends "base_manager.html" %}
{% block content %}
		<div class="page-header">
			<h1><i class="fa fa-file-text-o page-header-icon"></i>&nbsp;&nbsp;数据库 管理</h1>
			<button class="pull-right btn btn-primary" style="display: block;" id="backupdb"><i class="fa fa-print"></i>&nbsp;&nbsp;备份当前数据库</button>
		</div> <!-- / .page-header -->

       <div class="search-tabs">
        <ul class="nav nav-tabs">
            <li class="active">
                <a href="#search-tabs-all" data-toggle="tab">备份数据库 <span
                        class="label label-primary"></span></a>
            </li>

        </ul> <!-- / .nav -->
    </div>


   <div class="panel search-panel">
        <div class="panel-body tab-content">
            <!-- Classic search -->
            <div class="search-classic tab-pane fade in active" id="search-tabs-all">
               <table class="table table-hover">
						<thead>
							<tr>
								<th>#</th>
								<th>备份时间</th>
								<th>储存路径</th>
								<th>选择</th>
							</tr>
						</thead>
						<tbody>
                            {% for info in db_info %}
							<tr>
								<td>{{ forloop.counter }}</td>
                                <td>{{ info.date }}</td>
                                <td>{{ info.path }}</td>
								<td>
                                    <input type="checkbox" name="check" value="{{ info.path }}">
                                </td>
							</tr>
							{% endfor %}
						</tbody>

					</table>
            </div>

        </div>
   </div>


<button type="submit"  class="btn btn-facebook rounded" style="float: right;margin: 15px;" id="restore" >选择恢复</button>
    <script>
                   $("#restore").click(function () {
                        var len = $("input[name='check']:checked").length;
                        if (len===0){
                            alert("请选择一个文件进行还原！");
                            return false;
                        }
                        else if(len>1){
                            alert("只能选择一个文件！");
                            return false;
                        }
                        else {
                            var k = confirm("确认恢复?");
                            if (k){
                                var it = $("input[name='check']:checked").val();
                                var DATA = {};
                                DATA['restore'] = it;
                                $.ajax({
                                    type: "POST",
                                    dataType: "json",
                                    url: "/service/database_rollback/",
                                    data: DATA,
                                    success:function (respone) {
                                        if(respone['status']==200){
                                            alert('恢复成功');
                                            location.href='/service/database_show/';
                                        }
                                        else {
                                            alert("恢复失败");
                                            location.href='/service/database_show/';
                                        }

                                    }
                                })
                            }

                        }
                   })
               </script>
    </div>



	</div> <!-- / #content-wrapper -->
            <script>
                $("#backupdb").click(function () {
                    var i;
                    var DATA = {};
                    i = prompt("请输入文件名");
                    console.log(i);
                    if(i==null){
                        return;
                    }
                    DATA['backup'] = i;
                    $.ajax({
                        type: "POST",
                        url: "/service/database_backup/",
                        dataType: "json",
                        data: DATA,
                        success:function (respone) {
                            if(respone['status']==200){
                                alert('备份成功');
                                location.href='/service/database_show/';
                            }
                            else {
                                 alert("备份失败");
                                 location.href='/service/database_show/';
                            }

                        }
                    })

                })
            </script>


{% endblock %}